package cn.thoughtworks.school.programCenter.repositories;

import cn.thoughtworks.school.programCenter.entities.Assignment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface AssignmentRepository extends JpaRepository<Assignment, Long> {
    @Query("select assignment from Assignment assignment where taskId in ?1 order by orderNumber")
    List<Assignment> findByTaskIds(List<Long> taskIds);

    @Query("select programId from Task where id = (select taskId from Assignment where id = ?1)")
    Long findProgramIdByAssignmentId(Long AssignmentId);

    List<Assignment> findByTaskIdAndVisibleIsTrueOrderByOrderNumber(Long taskId);

    @Query("select assignment from Assignment assignment where taskId in (select id from Task task where task.programId = ?1)")
    List<Assignment> findByProgramId(Long programId);

    List<Assignment> findByTaskIdInAndVisibleIsTrue(List taskIds);


    List<Assignment> getAllByIdIn(List<Long> idList);
}
